import { http } from '@/utils/http/axios';

export interface BasicResponseModel<T = any> {
  status: number;
  message: string;
  data: T;
}

export interface BasicPageParams {
  pageNumber: number;
  pageSize: number;
  total: number;
}

/**
 * @description: 获取当前登录用户信息
 */
export function getUserInfo() {
  return http.request<BasicResponseModel>(
    {
      url: '/user/info',
      method: 'get',
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 获取用户信息
 */
export function getUserInfoById(id: number) {
  return http.request<BasicResponseModel>(
    {
      url: '/user/info',
      method: 'get',
      params: { userId: id },
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 添加用户信息
 */
export function addUserInfo(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/user/add',
      method: 'post',
      data: params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 更新用户信息
 */
export function updateUserInfo(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/user/update',
      method: 'post',
      data: params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 删除用户信息
 */
export function deleteUserInfo(userId: number) {
  return http.request<BasicResponseModel>(
    {
      url: `/user/delete?userId=${userId}`,
      method: 'post',
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户登录
 */
export function login(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/login',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
      withToken: false,
    }
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params, uid) {
  return http.request(
    {
      url: `/user/u${uid}/changepw`,
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户登出
 */
export function logout() {
  return http.request({
    url: '/logout',
    method: 'POST',
  });
}

/**
 * @description: 获取用户列表
 */
export function getUserList(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/user/list',
      method: 'get',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}
